import { Body, Controller, Delete, Get, HttpException, HttpStatus, Patch, Post, Put ,UseGuards} from '@nestjs/common';
import { ApiTags,ApiOkResponse} from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { PhotoService } from './photo.service';
import { Photo } from '../../../db/schemas/photo.schema';
import { AddPhoto ,EditPhoto , DeletePhoto } from './photo.dto'

/**相册模块控制器 */
@ApiTags('后台-相册模块')
@Controller('admin/photo')
export class PhotoController {
	constructor(
		private readonly photoService: PhotoService,
	) {}

	/**查-获取相册列表 */
	@UseGuards(AuthGuard('app-jwt'))
	@Get()
	async getPhoto(): Promise<Photo[]> {
		var rows=await this.photoService.findPhoto()
		return rows;
	}

	/**增-添加一条相册记录 */
	@Post()
	async addPhoto(@Body() Dto: AddPhoto): Promise<Boolean> {
		await this.photoService.addPhoto(Dto)
		return true

	}

	/**改-修改一条相册记录 */
	@Put()
	async updatePhoto(@Body() body: EditPhoto): Promise<Boolean> {
		await this.photoService.updatePhoto(body.id,body)
		return true
	}

	/**删-删除一条相册记录 */
	@Delete()
	async deletePhoto(@Body() body: DeletePhoto): Promise<Boolean> {
		await this.photoService.deletePhoto(body.id)
		return true
	}

	/**业务错误返回示例 */
	@Get('/error')
	testError(){
		throw new HttpException({
			code:123456,
			message:'错误示例。'
		},200)
	}
}
